using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using MAPDavy.Entities;

namespace MAPDavy.Repository.Mapping
{
	public class SeccionTutorMap : EntityTypeConfiguration<SeccionTutor>
	{
		public SeccionTutorMap()
		{
			// Primary Key
			this.HasKey(t => new { t.SeccionId, t.Anio });

			// Properties
			this.Property(t => t.SeccionId)
				.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
				
			this.Property(t => t.TutorId)
				.IsRequired()
				.IsFixedLength()
				.HasMaxLength(5);
				
			this.Property(t => t.Anio)
				.IsRequired()
				.IsFixedLength()
				.HasMaxLength(4);
				
			// Table & Column Mappings
			this.ToTable("SeccionTutor");
			this.Property(t => t.SeccionId).HasColumnName("SeccionId");
			this.Property(t => t.TutorId).HasColumnName("TutorId");
			this.Property(t => t.Anio).HasColumnName("Anio");
			this.Property(t => t.Comentario).HasColumnName("Comentario");

			// Relationships
			this.HasRequired(t => t.AnioLectivo)
				.WithMany(t => t.SeccionTutors)
				.HasForeignKey(d => d.Anio);
				
			this.HasRequired(t => t.Seccion)
				.WithMany(t => t.SeccionTutors)
				.HasForeignKey(d => d.SeccionId);
				
			this.HasRequired(t => t.Tutor)
				.WithMany(t => t.SeccionTutors)
				.HasForeignKey(d => d.TutorId);
				
		}
	}
}

